package com.lizard.schedule.ui.activity.base;

import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;

import com.google.android.gms.wearable.Node;
import com.lizard.schedule.manager.ObserverIfaces;
import com.lizard.schedule.manager.ObserverManager;

/**
 * 特性:
 * 1、监听与手持设备的连接状态
 * 2、连接中断后将自动关闭界面 若想要修改本特性可重写{@link #onConnectChanged(boolean, Node)}方法覆盖
 *
 * Created by wangyiqian on 16/6/12.
 */
public class BaseActivity extends WearableActivity implements ObserverIfaces.HandsetConnectChangedListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ObserverManager.getInstance().addHandsetConnectChangedListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ObserverManager.getInstance().removetHandsetConnectChangedListener(this);
    }

    /**
     * 与手机的连接状态发生变化
     *
     * @param connected
     */
    @Override
    public void onConnectChanged(boolean connected, Node peer) {
        if(!connected){
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    finish();
                }
            });
        }
    }
}
